package com.auxgroup.hr.front.service.modperson.impl;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCModEmpLang;
import com.auxgroup.hr.front.dao.domain.PsCModPerPrimary;
import com.auxgroup.hr.front.dao.repository.PsCModEmpLangRepository;
import com.auxgroup.hr.front.service.modperson.ModEmpLangService;

/** 
 * @author lvliuhao
 * @version 创建时间：180526 
 * 语言能力流程信息service
 */
@Service("modEmpLangService")
public class ModEmpLangServiceImpl implements ModEmpLangService {
	private static final Logger logger = LoggerFactory.getLogger(ModEmpLangServiceImpl.class);
	
	@Autowired
	private PsCModEmpLangRepository PsCModEmpLangRepository;


	@Override
	public PsCModEmpLang getModEmpLang(PsCModPerPrimary modPerPrimary) {
		return PsCModEmpLangRepository.findOne(modPerPrimary);
	}


	@Override
	public PsCModEmpLang save(PsCModEmpLang ModEmpLang,UserDTO user) {
		ModEmpLang.setHrsRowAddOprid(user.getOprId());
		ModEmpLang.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
		ModEmpLang.setHrsRowUpdOprid(user.getOprId());
		ModEmpLang.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
		Set<String> ignoreFields = new HashSet<String>(Arrays.asList("cSeqno"));
		ObjectFieldUtils.handleNullValue(ModEmpLang,ignoreFields);
		return PsCModEmpLangRepository.save(ModEmpLang);
	}


	@Override
	public Boolean delete(PsCModPerPrimary modPerPrimary) {
		try {
			PsCModEmpLangRepository.delete(modPerPrimary);
		} catch (Exception e) {
			logger.error("delete ModEmpLang error: modPerPrimary={}",modPerPrimary,e);
			return false;
		}
		return true;
	}
	
	
	@Override
	public List<PsCModEmpLang> getAll(String emplid) {
		PsCModEmpLang ModEmpLang = new PsCModEmpLang();
		ModEmpLang.setEmplid(emplid);
		return PsCModEmpLangRepository.findAll(Example.of(ModEmpLang));
	}


	/* (non-Javadoc)
	 * @see ModEmpLangService#getAll(java.lang.String, java.lang.String)
	 */
	@Override
	public List<PsCModEmpLang> getAll(String cTransactionNbr, String emplid) {
		PsCModEmpLang ModEmpLang = new PsCModEmpLang();
		ModEmpLang.setEmplid(emplid);
		ModEmpLang.setcTransactionNbr(cTransactionNbr);
		return PsCModEmpLangRepository.findAll(Example.of(ModEmpLang));
	}


	
	
	
}
